/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            orderWriteOffConfirmInfo: {
                orders: [],
                woNum: '',
                total: 0,
                records: 1,
                moreCondition: false,
                conditions: {
                    personName: '',
                    woNum: '',
                    shopId: ''
                }
            }
        },
        _initMethod: function () {
            $that._listOrderWriteOffConfirms(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listOrderWriteOffConfirms(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listOrderWriteOffConfirms: function (_page, _rows) {
                $that.orderWriteOffConfirmInfo.conditions.page = _page;
                $that.orderWriteOffConfirmInfo.conditions.row = _rows;
                $that.orderWriteOffConfirmInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                let param = {
                    params: $that.orderWriteOffConfirmInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/storeOrder.listStoreOrderWriteoff',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.orderWriteOffConfirmInfo.total = _json.total;
                        $that.orderWriteOffConfirmInfo.records = _json.records;
                        $that.orderWriteOffConfirmInfo.orders = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.orderWriteOffConfirmInfo.records,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _confirmWriteOffOrder: function () {
                let _woNum = $that.orderWriteOffConfirmInfo.woNum;
                if (!_woNum) {
                    vc.toast('请扫码');
                    return;
                }
                let _data = {
                    woNum: _woNum,
                    shopId: vc.getCurrentCommunity().shopId
                }
                vc.http.apiPost(
                    '/storeOrder.confirmWriteOffOrder',
                    JSON.stringify(_data), {
                    emulateJSON: true
                },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        $that.orderWriteOffConfirmInfo.timeId = '';
                        let _json = JSON.parse(json);
                        if (_json.code != 0) {
                            vc.toast(_json.msg);
                            return;
                        }
                        vc.toast("核销成功");
                        $that._listOrderWriteOffConfirms(1, 10);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        $that.orderWriteOffConfirmInfo.timeId = '';
                        vc.toast(errInfo);
                    });
            },
            _moreCondition: function () {
                if ($that.orderWriteOffConfirmInfo.moreCondition) {
                    $that.orderWriteOffConfirmInfo.moreCondition = false;
                } else {
                    $that.orderWriteOffConfirmInfo.moreCondition = true;
                }
            },
            //查询
            _queryOrderWriteOffConfirmMethod: function () {
                $that._listOrderWriteOffConfirms(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetOrderWriteOffConfirmMethod: function () {
                $that.orderWriteOffConfirmInfo.conditions.personName = "";
                $that.orderWriteOffConfirmInfo.conditions.personTel = "";
                $that.orderWriteOffConfirmInfo.conditions.appointmentTime = "";
                $that._listOrderWriteOffConfirms(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openOrderDetailModel: function(_order) {
                vc.jumpToPage('/#/pages/goods/storeOrderCartDetail?orderId=' + _order.orderId);
            },
        }
    });
})(window.vc);